const fs = require("fs");
// 检查配置文件是否存在
const path_config_fn = require("../utils/path");
// 文件路径
const { path_config_config_json } = require("../constant/index");


module.exports.getConfig = (key) => {
  path_config_fn();

  let data = fs.readFileSync(path_config_config_json);

  data = JSON.parse(data);
  return data[key];
};

module.exports.setConfig = (key, value) => {
  path_config_fn();

  let data = fs.readFileSync(path_config_config_json);

  data = JSON.parse(data);

  data = { ...data, [key]: value };
  fs.writeFileSync(path_config_config_json, JSON.stringify(data));

  return true;
};
